using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovePlatform : MonoBehaviour
{
    private Rigidbody2D rb;
    //private Animator anim;
    private Transform top, bottom, Boundaries;
    private float topPoint, bottomPoint;
    public float speed;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();

        Boundaries = transform.GetChild(0).GetChild(0);
        top = Boundaries.GetChild(0);
        bottom = Boundaries.GetChild(1);
        transform.GetChild(0).DetachChildren();

        topPoint = top.position.y;
        bottomPoint = bottom.position.y;
        Destroy(Boundaries.gameObject);
    }

    void FixedUpdate()
    {
        Movement();
    }

    void Movement()
    {
        rb.velocity = new Vector2(rb.velocity.x, speed * Time.deltaTime);
        if (transform.position.y > topPoint || transform.position.y < bottomPoint)
        {
            speed = speed * -1;
            rb.velocity = new Vector2(rb.velocity.x, speed * Time.deltaTime);
        }
    }
}
